// Tierless
// Copyright © 2010 Alphora
// This file is licensed under a modified BSD-license (see tierless_license.txt).
using System;
using System.Runtime.Serialization;

namespace Tierless.Framework.Constraints
{
	/// <summary>
	/// Represents the possible violation severities.
	/// </summary>
	public enum ViolationSeverity
	{
		/// <summary>
		/// The violation is an error, and prevents the change from being made.
		/// </summary>
		Error,

		/// <summary>
		/// The violation is a warning, and should be displayed to the user, but does not prevent the change from being made.
		/// </summary>
		Warning
	}

	/// <summary>
	/// Represents a constraint violation.
	/// </summary>
	[DataContract]
	public class ConstraintViolation
	{
		/// <summary>
		/// Constructs a new instance of a constraint violation.
		/// </summary>
		/// <param name="constraintName">The name of the constraint that was violated.</param>
		/// <param name="entityTypeName">The entity type on which the violation occurred.</param>
		/// <param name="columnNames">The names of the columns involved in the violation.</param>
		/// <param name="triggeringColumnNames">The names of the columns that were changed, triggering the validation.</param>
		/// <param name="severity">The severity of the violation.</param>
		/// <param name="message">The message for the violation.</param>
		public ConstraintViolation(string constraintName, string entityTypeName, string[] columnNames, string[] triggeringColumnNames, ViolationSeverity severity, string message)
		{
			if (constraintName == null) throw new ArgumentNullException("AConstraintName");
			if (entityTypeName == null) throw new ArgumentNullException("AEntityTypeName");
			if (columnNames == null) throw new ArgumentNullException("AColumnNames");
			if (triggeringColumnNames == null) throw new ArgumentNullException("ATriggeringColumnNames");
			if (message == null) throw new ArgumentNullException("AMessage");

			ConstraintName = constraintName;
			EntityTypeName = entityTypeName;
			ColumnNames = columnNames;
			TriggeringColumnNames = triggeringColumnNames;
			Severity = severity;
			Message = message;
		}

		/// <summary>
		/// Gets the name of the constraint that was violated.
		/// </summary>
		[DataMember]
		public string ConstraintName { get; private set; }

		/// <summary>
		/// Gets the entity type on which the violation occurred.
		/// </summary>
		[DataMember]
		public string EntityTypeName { get; private set; }

		/// <summary>
		/// Gets the names of the columns involved in the violation.
		/// </summary>
		[DataMember]
		public string[] ColumnNames { get; private set; }

		/// <summary>
		/// Gets the names of the columns that were changed, triggering the validation.
		/// </summary>
		[DataMember]
		public string[] TriggeringColumnNames { get; private set; }

		/// <summary>
		/// Gets the severity of the violation.
		/// </summary>
		[DataMember]
		public ViolationSeverity Severity { get; private set; }

		/// <summary>
		/// Gets the message of the violation.
		/// </summary>
		[DataMember]
		public string Message { get; private set; }
	}
}